package top.ranzhang.controller.admin;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.ranzhang.bean.dto.AdminLoginDTO;
import top.ranzhang.bean.dto.EmailOtherDTO;
import top.ranzhang.bean.vo.AdminVO;
import top.ranzhang.common.context.BaseContext;
import top.ranzhang.common.result.Result;
import top.ranzhang.service.IAdminService;

/**
 * 管理员
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/admin")
public class AdminController {

    private final IAdminService adminService;


    /**
     * 登录
     * @param adminLoginDTO
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody AdminLoginDTO adminLoginDTO){
        AdminVO result = adminService.login(adminLoginDTO);
        return Result.success(result, "登录成功");
    }

    /**
     * 退出
     * @return
     */
    @GetMapping("/logout")
    public Result logout(){
        BaseContext.removeCurrentId();
        return Result.success();
    }


    /**
     * 获取字符验证码
     * @return
     */
    @GetMapping("/getCode")
    public Result getCode(){
        String code = adminService.getEmailCode();
        return Result.success(code);
    }


}
